home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / term / linux.trm < prev    next >
Encoding:
Text File  |  1999-08-19  |  8.4 KB  |  338 lines

  1. /*
  2.  * $Id: lT_HELP(linux)
  3. "1.1 1999/08/19 14:17:16 lhecking Exp $
  4.  *
  5.  */
  6.  
  7. /* GNUPLOT - linux.trm */
  8.  
  9. /*[
  10.  * Copyright 1993, 1998
  11.  *
  12.  * Permission to use, copy, and distribute this software and its
  13.  * documentation for any purpose with or without fee is hereby granted,
  14.  * provided that the above copyright notice appear in all copies and
  15.  * that both that copyright notice and this permission notice appear
  16.  * in supporting documentation.
  17.  *
  18.  * Permission to modify the software is granted, but not the right to
  19.  * distribute the complete modified source code.  Modifications are to
  20.  * be distributed as patches to the released version.  Permission to
  21.  * distribute binaries produced by compiling modified sources is granted,
  22.  * provided you
  23.  *   1. distribute the corresponding source modifications from the
  24.  *    released version in the form of a patch file along with the binaries,
  25.  *   2. add special version identification to distinguish your version
  26.  *    in addition to the base release version number,
  27.  *   3. provide your name and address as the primary contact for the
  28.  *    support of your modified version, and
  29.  *   4. retain our contact information in regard to use of the base
  30.  *    software.
  31.  * Permission to distribute the released version of the source code along
  32.  * with corresponding source modifications in the form of a patch file is
  33.  * granted with same provisions 2 through 4 for binary distributions.
  34.  *
  35.  * This software is provided "as is" without express or implied warranty
  36.  * to the extent permitted by applicable law.
  37. ]*/
  38.  
  39. /*
  40.  * This file is included by ../term.c.
  41.  *
  42.  * This terminal driver supports:
  43.  *  SVGA up to 1024x768x256 for PC's running the Linux Operating System
  44.  *  (also VGA 640x480x16, and SVGA 800x600x256)
  45.  *
  46.  * AUTHOR
  47.  *  Scott Heavner (sdh@po.cwru.edu)
  48.  *  based on original linux.trm by Tommy Frandsen (frandsen@diku.dk)
  49.  *  patched by David J. Liu (liu@molecule.phri.nyu.edu)
  50.  *  to increase perfomance and safety based on the features of SVGALib/GL.
  51.  *  send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  52.  */
  53.  
  54. /*
  55.  * Compile with Linux SVGAlib 0.95 currently maintained by
  56.  * Harm Hanemaayer (hhanemaa@cs.ruu.nl).
  57.  * supports Trident, Tseng, Cirrus, Oak and generic vga.
  58.  */
  59.  
  60. #include "driver.h"
  61.  
  62. #ifdef TERM_REGISTER
  63. register_term(linux)
  64. #endif
  65.  
  66. #ifdef TERM_PROTO
  67.  
  68. #define LINUX_VCHAR FNT5X9_VCHAR
  69. #define LINUX_HCHAR FNT5X9_HCHAR
  70. #define LINUX_VTIC 5
  71. #define LINUX_HTIC 5
  72. #define LINUX_XMAX 0        /* These two entries are just place holders. */
  73. #define LINUX_YMAX 0        /* The actual values will be filled in init. */
  74.  
  75. TERM_PUBLIC void LINUX_options __PROTO((void));
  76. TERM_PUBLIC void LINUX_init __PROTO((void));
  77. TERM_PUBLIC void LINUX_reset __PROTO((void));
  78. TERM_PUBLIC void LINUX_text __PROTO((void));
  79. TERM_PUBLIC void LINUX_graphics __PROTO((void));
  80. TERM_PUBLIC void LINUX_linetype __PROTO((int linetype));
  81. TERM_PUBLIC void LINUX_move __PROTO((unsigned int x, unsigned int y));
  82. TERM_PUBLIC void LINUX_vector __PROTO((unsigned int x, unsigned int y));
  83. TERM_PUBLIC int LINUX_text_angle __PROTO((int ang));
  84. TERM_PUBLIC void LINUX_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
  85. TERM_PUBLIC void LINUX_suspend __PROTO((void));
  86. TERM_PUBLIC void LINUX_resume __PROTO((void));
  87.  
  88. #endif
  89.  
  90. #ifdef TERM_BODY
  91.  
  92. #define _STRING_H_
  93. #include <vga.h>
  94.  
  95. static int linux_vmode = G1024x768x256;        /* default mode */
  96. static int vgacolor[] = { 7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6 };
  97. static int graphics_on = FALSE;
  98. vga_modeinfo *modeinfo;
  99. static int linux_startx, linux_starty, linux_lasty;
  100. static int linux_angle;
  101. int LINUX_graphics_allowed;
  102. extern void drop_privilege();
  103. extern void take_privilege();
  104.  
  105. typedef (*linux_line_func_ptr) __PROTO((int x1, int y1, int x2, int y2));
  106.  
  107. static void LINUX_putc __PROTO((unsigned int x, unsigned int y, int c, int ang,
  108.                 linux_line_func_ptr line_func));
  109.  
  110. /* this function is called at the very beginning of main() to initialize
  111.  *  the vgalib and to revoke suid privileges.
  112.  * /dev/console and /dev/tty\d are considered graphic terminals, all other
  113.  * don't support the linux terminal */
  114.  
  115. void
  116. LINUX_setup(void)
  117. {
  118.     char line[256];
  119.     FILE *pipe;
  120.  
  121.     LINUX_graphics_allowed = FALSE;
  122.  
  123.     if (geteuid() != 0)
  124.     return;            /* if we aren't root, we cannot init graphics */
  125.  
  126.     if ((pipe = popen("/usr/bin/tty", "r")) != NULL) {
  127.     line[0] = 0;
  128.     fgets(line, 256, pipe);
  129.     pclose(pipe);
  130.     line[strlen(line) - 1] = '\0';
  131.     if (strcmp(line, "/dev/console") == 0 ||
  132.         (strncmp(line, "/dev/tty", 8) == 0 && isdigit(line[8])))
  133.         LINUX_graphics_allowed = TRUE;
  134.     }
  135.     if (LINUX_graphics_allowed) {
  136.     take_privilege();
  137.     vga_init();
  138.     drop_privilege();
  139.     } else {
  140.     /* err - shouldn't we give up root uid whatever happens ?
  141.      * or perhaps vga_init() does it ?
  142.      */
  143.     setuid(getuid());
  144.     }
  145. }
  146.  
  147. TERM_PUBLIC
  148. void LINUX_options()
  149. {
  150.     if (!LINUX_graphics_allowed) {
  151.     int_error("Linux terminal driver not available",NO_CARET);
  152.     }
  153.     fprintf(stderr, "%s\n", vga_getmodename(linux_vmode));
  154. }
  155.  
  156. TERM_PUBLIC
  157. void LINUX_init()
  158. {
  159.     /* vga_init () has been moved to immediately after main () for security */
  160.     if (vga_getdefaultmode() != -1)
  161.     linux_vmode = vga_getdefaultmode();
  162.     /* get the default mode from GSVGAMODE, if available */
  163.     if (!vga_hasmode(linux_vmode))
  164.     linux_vmode = G640x480x16;
  165.     /* test default mode first */
  166.     if (!vga_hasmode(linux_vmode)) {
  167.     fputs("Error, unable to initiate graphics.\n", stderr);
  168.     return;
  169.     }                /* this mode is the bottom line */
  170.     modeinfo = vga_getmodeinfo(linux_vmode);
  171.     term->xmax = modeinfo->width;
  172.     term->ymax = modeinfo->height;
  173.     linux_lasty = modeinfo->height - 1;
  174. }
  175.  
  176. TERM_PUBLIC void
  177. LINUX_reset()
  178. {
  179.     if (graphics_on) {
  180.     vga_setmode(TEXT);
  181.     graphics_on = FALSE;
  182.     }
  183. }
  184.  
  185. TERM_PUBLIC void
  186. LINUX_text()
  187. {
  188.     if (graphics_on) {
  189.     vga_getch();
  190.     vga_setmode(TEXT);
  191.     graphics_on = FALSE;
  192.     }
  193. }
  194.  
  195. TERM_PUBLIC void
  196. LINUX_graphics()
  197. {
  198.     if (!graphics_on) {
  199.     vga_setmode(linux_vmode);
  200.     graphics_on = TRUE;
  201.     }
  202. }
  203.  
  204. TERM_PUBLIC void
  205. LINUX_suspend()
  206. {
  207.     vga_flip();
  208. }
  209.  
  210. TERM_PUBLIC void
  211. LINUX_resume()
  212. {
  213.     vga_flip();
  214. }
  215.  
  216. TERM_PUBLIC void
  217. LINUX_linetype(linetype)
  218. int linetype;
  219. {
  220.     if (linetype >= 13)
  221.     linetype %= 13;
  222.     vga_setcolor(vgacolor[linetype + 2]);
  223. }
  224.  
  225. TERM_PUBLIC void
  226. LINUX_move(x, y)
  227. unsigned int x;
  228. unsigned int y;
  229. {
  230.     linux_startx = x;
  231.     linux_starty = y;
  232. }
  233.  
  234. TERM_PUBLIC void
  235. LINUX_vector(x, y)
  236. unsigned int x;
  237. unsigned int y;
  238. {
  239.     vga_drawline(linux_startx, linux_lasty - linux_starty, x, linux_lasty - y);
  240.     linux_startx = x;
  241.     linux_starty = y;
  242. }
  243.  
  244. TERM_PUBLIC int
  245. LINUX_text_angle(ang)
  246. int ang;
  247. {
  248.     linux_angle = ang;
  249.     return TRUE;
  250. }
  251.  
  252. static void
  253. LINUX_putc(x, y, c, ang, line_func)
  254. unsigned int x, y;
  255. int c;
  256. int ang;
  257. linux_line_func_ptr line_func;
  258. {
  259.     int i, j, k;
  260.     unsigned int pixelon;
  261.     i = (int) (c) - 32;
  262.     for (j = 0; j < FNT5X9_VBITS; j++) {
  263.     for (k = 0; k < FNT5X9_HBITS; k++) {
  264.         pixelon = (((unsigned int) (fnt5x9[i][j])) >> k & 1);
  265.         if (pixelon) {
  266.         switch (ang) {
  267.         case 0:
  268.             (*line_func) (x + k + 1, y - j, x + k + 1, y - j);
  269.             break;
  270.         case 1:
  271.             (*line_func) (x - j, y - k - 1, x - j, y - k - 1);
  272.             break;
  273.         }
  274.         }
  275.     }
  276.     }
  277. }
  278.  
  279. TERM_PUBLIC void
  280. LINUX_put_text(x, y, str)
  281. unsigned int x, y;
  282. const char *str;
  283. {
  284.     int i;
  285.     switch (linux_angle) {
  286.     case 0:
  287.     y -= LINUX_VCHAR / 2;
  288.     break;
  289.     case 1:
  290.     x += LINUX_VCHAR / 2;
  291.     break;
  292.     }
  293.     for (i = 0; str[i]; i++) {
  294.     LINUX_putc(x, linux_lasty - y, str[i], linux_angle, vga_drawline);
  295.     switch (linux_angle) {
  296.     case 0:
  297.         x += LINUX_HCHAR;
  298.         break;
  299.     case 1:
  300.         y += LINUX_HCHAR;
  301.         break;
  302.     }
  303.     }
  304. }
  305.  
  306. #endif
  307.  
  308. #ifdef TERM_TABLE
  309. TERM_TABLE_START(linux_driver)
  310.     "linux", "Linux PC with (s)vgalib",
  311.     LINUX_XMAX, LINUX_YMAX, LINUX_VCHAR, LINUX_HCHAR,
  312.     LINUX_VTIC, LINUX_HTIC, LINUX_options, LINUX_init, LINUX_reset,
  313.     LINUX_text, null_scale, LINUX_graphics, LINUX_move, LINUX_vector,
  314.     LINUX_linetype, LINUX_put_text, LINUX_text_angle,
  315.     null_justify_text, do_point, do_arrow, set_font_null,
  316.     0,                /* pointsize */
  317.     TERM_CAN_MULTIPLOT, LINUX_suspend, LINUX_resume
  318. TERM_TABLE_END(linux_driver)
  319. #undef LAST_TERM
  320. #define LAST_TERM linux_driver
  321. #endif
  322.  
  323. #ifdef TERM_HELP
  324. START_HELP(linux)
  325. "1 linux",
  326. "?commands set terminal linux",
  327. "?set terminal linux",
  328. "?set term linux",
  329. "?terminal linux",
  330. "?term linux",
  331. "?linux",
  332. " The `linux` driver has no additional options to specify.  It looks at the",
  333. " environment variable GSVGAMODE for the default mode; if not set, it uses",
  334. " 1024x768x256 as default mode or, if that is not possible, 640x480x16",
  335. " (standard VGA)."
  336. END_HELP(linux)
  337. #endif
  338.